/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.src.uniandes.ecos.tsp.creditscore.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author AndhyMao
 */
@Entity
@Table(name = "tbl_historial_crediticio")
@NamedQueries({@NamedQuery(name = "HistorialCrediticio.findAll", query = "SELECT h FROM HistorialCrediticio h"), @NamedQuery(name = "HistorialCrediticio.findByHcrCodigo", query = "SELECT h FROM HistorialCrediticio h WHERE h.hcrCodigo = :hcrCodigo"), @NamedQuery(name = "HistorialCrediticio.findByHcrAnirep", query = "SELECT h FROM HistorialCrediticio h WHERE h.hcrAnirep = :hcrAnirep"), @NamedQuery(name = "HistorialCrediticio.findByHcrMesrep", query = "SELECT h FROM HistorialCrediticio h WHERE h.hcrMesrep = :hcrMesrep"),
@NamedQuery(name = "HistorialCrediticio.findByHcrAnirepHcrMesrep",query = "select hc from HistorialCrediticio hc where hc.clienteProducto.cliente.cliCodigo = :idCliente and hc.clienteProducto.clienteProductoPK.clpNumpro = :idProducto and hc.hcrAnirep = (select max(hc1.hcrAnirep) from HistorialCrediticio hc1 where hc1.clienteProducto.cliente.cliCodigo = :idCliente and hc1.clienteProducto.clienteProductoPK.clpNumpro = :idProducto) and hc.hcrMesrep =(select max(hc2.hcrMesrep) from HistorialCrediticio hc2 where hc2.clienteProducto.cliente.cliCodigo = :idCliente and hc2.clienteProducto.clienteProductoPK.clpNumpro = :idProducto)"),
@NamedQuery(name = "HistorialCrediticio.count24MonthsDebt", query="select count(hc) from HistorialCrediticio hc where hc.clienteProducto.clienteProductoPK.cliCodigo = :idCliente and hc.clienteProducto.clienteProductoPK.clpNumpro = :idProducto and hc.ereCodigo.ereCodigo in (2,3) and hc.hcrAnirep >= :hcrAnirep and hc.hcrMesrep >= :hcrMesrep"),
@NamedQuery(name = "HistorialCrediticio.count12MonthsDebt", query="select count(hc) from HistorialCrediticio hc where hc.clienteProducto.clienteProductoPK.cliCodigo = :idCliente and hc.clienteProducto.clienteProductoPK.clpNumpro = :idProducto and hc.ereCodigo.ereCodigo = :ereCodigo and hc.hcrAnirep >= :hcrAnirep and hc.hcrMesrep >= :hcrMesrep"),
@NamedQuery(name = "HistorialCrediticio.count12-24MonthsDebt", query="select count(hc) from HistorialCrediticio hc where hc.clienteProducto.clienteProductoPK.cliCodigo = :idCliente and hc.clienteProducto.clienteProductoPK.clpNumpro = :idProducto and hc.ereCodigo.ereCodigo = :ereCodigo and hc.hcrAnirep <= :hcrAnirep1 and hc.hcrMesrep <= :hcrMesrep1 and hc.hcrAnirep >= :hcrAnirep and hc.hcrMesrep >= :hcrMesrep")})
public class HistorialCrediticio implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "hcr_codigo")
    private Integer hcrCodigo;
    @Column(name = "hcr_anirep")
    private Short hcrAnirep;
    @Column(name = "hcr_mesrep")
    private Short hcrMesrep;
    @JoinColumns({@JoinColumn(name = "cli_codigo", referencedColumnName = "cli_codigo"), @JoinColumn(name = "pro_codigo", referencedColumnName = "pro_codigo"), @JoinColumn(name = "clp_numpro", referencedColumnName = "clp_numpro")})
    @ManyToOne
    private ClienteProducto clienteProducto;
    @JoinColumn(name = "ere_codigo", referencedColumnName = "ere_codigo")
    @ManyToOne
    private EstadoReporte ereCodigo;

    public HistorialCrediticio() {
    }

    public HistorialCrediticio(Integer hcrCodigo) {
        this.hcrCodigo = hcrCodigo;
    }

    public Integer getHcrCodigo() {
        return hcrCodigo;
    }

    public void setHcrCodigo(Integer hcrCodigo) {
        this.hcrCodigo = hcrCodigo;
    }

    public Short getHcrAnirep() {
        return hcrAnirep;
    }

    public void setHcrAnirep(Short hcrAnirep) {
        this.hcrAnirep = hcrAnirep;
    }

    public Short getHcrMesrep() {
        return hcrMesrep;
    }

    public void setHcrMesrep(Short hcrMesrep) {
        this.hcrMesrep = hcrMesrep;
    }

    public ClienteProducto getClienteProducto() {
        return clienteProducto;
    }

    public void setClienteProducto(ClienteProducto clienteProducto) {
        this.clienteProducto = clienteProducto;
    }

    public EstadoReporte getEreCodigo() {
        return ereCodigo;
    }

    public void setEreCodigo(EstadoReporte ereCodigo) {
        this.ereCodigo = ereCodigo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (hcrCodigo != null ? hcrCodigo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof HistorialCrediticio)) {
            return false;
        }
        HistorialCrediticio other = (HistorialCrediticio) object;
        if ((this.hcrCodigo == null && other.hcrCodigo != null) || (this.hcrCodigo != null && !this.hcrCodigo.equals(other.hcrCodigo))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.src.uniandes.ecos.tsp.creditscore.entity.HistorialCrediticio[hcrCodigo=" + hcrCodigo + "]";
    }

}
